import {call,put} from 'redux-saga/effects'
import axios from '../utils/request'
import { message} from 'antd';

export function * getFormat({payload}){//获取规格
    console.log(payload,'getFormat-payload')
    const res=yield call(axios,{url:'/api/shopformat',method:'get',params:payload})
    console.log(res)
    if(res.code===1){
        yield put({
            type:'GET_FORMAT',
            payload:res.data
        })
    }else{
        yield put({
            type:'GET_FORMAT',
            payload:res.data
        })
    }
}

export function * edmitFormat({payload}){  //编辑
    console.log(payload,'edmit-payload')
    const res=yield call(axios,{url:'/api/edmitformat',method:'put',data:payload})
    console.log(res)
    if(res.code===1){
        message.success(res.data.msg);
    }else{
        message.error(res.data.msg);
    }
}

export function * getDetail({payload}){//获取详情
    const res=yield call(axios,{url:`/api/shopdetail/${payload}`})
    console.log(res)
}

export function * delFormat({payload}){//删除规格
    console.log(payload)
    const res=yield call(axios,{url:`/api/delformat/${payload}`,method:'delete'})
    console.log(res)
    if(res.code===1){
        message.success(res.data.msg);
    }else{
        message.error(res.data.msg);
    }
}

export function * addFormat({payload}){//新增规格
    console.log(payload,'add-payload')
    const res=yield call(axios,{url:'/api/addformat',method:'post',data:payload})
    console.log(res)
    if(res.code===1){
        message.success(res.data.msg);
    }else{
        message.error(res.data.msg);
    }
}